#include "command.h"
#include "key_process.h"

#define PROG_BAR_LEN 60
#define COMPLETED_SYM '#'
#define REMAINING_SYM '='
#define hl(string) (WHITE_HL string RESET)

void exit_prog_bar()
{
	printf(HIDE_CUR);
    char prog_bar[PROG_BAR_LEN];
    memset(prog_bar, REMAINING_SYM, PROG_BAR_LEN);
    prog_bar[PROG_BAR_LEN] = '\0';
    int pos = 0;
    int total_steps = PROG_BAR_LEN;
    int sleep_time = 3;
    int step_time = sleep_time * 1000000 / total_steps;
    
    printf("%s %s [%d%s]", hl("Exit..."), prog_bar, 0, "%");
    fflush(stdout);
    
    for (int i = 0; i < total_steps; i++) {
		printf(MOVE_CUR_BL);
        usleep(step_time / 2 + rand() % (step_time / 2)); 
        prog_bar[pos] = COMPLETED_SYM;
        pos++;
        printf(CLL); 
        
        char pass_bar[PROG_BAR_LEN];
        strncpy(pass_bar, prog_bar, pos);
        pass_bar[pos] = '\0';
        
        printf("%s %s%s%s%s [%d%s]", hl("Exit..."), MAGENTA_BG, pass_bar, RESET, &prog_bar[pos], pos * 100 / total_steps, "%");
        fflush(stdout);
    }

    printf(DISPLAY_CUR);
	printf("\n");
}
